package com.pxml2pdf.pdf.Node;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.pxml2pdf.pdf.PageManger;

public class LabelNode extends BaseNode {
	private static final float LABLE_EX = 4F;
	private static final String UNDO = "pimRecordStatus";
	private boolean can_ex = true;

	public boolean isCan_ex() {
		return can_ex;
	}

	public void setCan_ex(boolean can_ex) {
		this.can_ex = can_ex;
	}

	@Override
	public void drawingBox(PdfContentByte cb) {
		// cb.setLineWidth(0.4f);
		// cb.setColorStroke(LINE_COLOR);
		// cb.roundRectangle(getLlx(), getLly(), getUrx() - getLlx(), getUry() -
		// getLly(), 5);
		// cb.stroke();
	}

	@Override
	public void fillValue(PdfContentByte cb, Font font) throws DocumentException {
		if (UNDO.equals(getId()))
			return;
		String str = getValue().trim();
//		 System.out.println(str);
//		 System.out.println(font.getFamilyname());
//		 System.out.println(getFontStr());
		if (can_ex)
			setUrx(getUrx() + LABLE_EX);
		int pos = str.lastIndexOf(STAR);
		if (pos >= 0 && (pos + 1) == str.length()) {
			str = str.substring(0, pos).trim();
			Phrase phrase = new Phrase(str, font);
			FONT_STAR.setSize(font.getSize());

			Phrase phrase_Star = new Phrase(STAR, FONT_STAR);
			ColumnText ct = new ColumnText(cb);
			ct.setSimpleColumn(getLlx(), getLly(), getUrx(), getUry(), LEADING, getAlign());
			ct.addText(phrase);
			ct.addText(phrase_Star);
			ct.go();
		} else {
			if (getHmtlFontSize() >= 17f) {
				setUrx(PageManger.PAGE_WIDTH);
			}

			super.fillValue(cb, font);
		}
	}

}
